package com.yan_jiu_sheng.LeetCodeHot100.AC;

/**
 * https://leetcode.cn/problems/subarray-sum-equals-k/description/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 * 还未看题解 (前缀树)
 *
 * @author yulongTian
 * @create 2024-05-26 21:24
 */
public class Test10 {
    public static void main(String[] args) {
        System.out.println(subarraySum(new int[]{1, -1, 0}, 0));
    }

    public static int subarraySum(int[] nums, int k) {
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            int sum = 0;
            for (int j = i; j < nums.length; j++) {
                sum += nums[j];
                if (sum == k) {
                    res++;
                }
            }
        }
        return res;
    }

}
